package com.guigu.www.erp.tangyingmeng.controller;

import com.guigu.www.erp.common.pojo.DFile;
import com.guigu.www.erp.common.pojo.PageVo;
import com.guigu.www.erp.dehao.pojo.User;
import com.guigu.www.erp.tangyingmeng.service.TYMDFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.awt.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("TYMDfile")
public class TYMDfileController {

    @Autowired
    private TYMDFileService service;


    @GetMapping("{productName}")
    public int extis(@PathVariable("productName") String productName){
        return service.existence(productName);
    }

    @PostMapping("insert")
    public int insert(@RequestBody DFile dFile,HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        return service.DfileInsert(dFile,user.getUserName());
    }

    @PostMapping("selfuhe")
    public PageVo<DFile> selfuhe(@RequestBody Map<String,String> map, HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        PageVo<DFile> pageVo = service.selfuhe(map,user.getDeptId());
        User loginUser = (User) session.getAttribute("loginUser");
        if (loginUser.getRole().getRoleId()==4){
            return null;
        }else {
            return pageVo;
        }
    }

    @PostMapping("{fileId}")
    public DFile fuheselbyone(@PathVariable("fileId") int fileId){
        return service.fuheselbyone(fileId);
    }

    @PostMapping("zhun/{productId}")
    public int FuHePiZhun(@PathVariable("productId") String productId, HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        return service.FuHePiZhun(productId,user.getUserName());
    }

    @PutMapping("bu/{productId}")
    public int FuHeBuZhun(@PathVariable("productId") String productId, HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        return service.FuHeBuZhun(productId,user.getUserName());
    }

    @PostMapping("selall")
    public PageVo<DFile> selall(@RequestBody Map<String,String> map){
        PageVo<DFile> pageVo = service.selall(map);
        return pageVo;
    }

    @PostMapping("selsc")
    public PageVo<DFile> selsc(@RequestBody Map<String,String> map){
        PageVo<DFile> pageVo = service.selsc(map);
        return pageVo;
    }

    @PostMapping("selhf")
    public PageVo<DFile> selhf(@RequestBody Map<String,String> map){
        PageVo<DFile> pageVo = service.selhf(map);
        return pageVo;
    }

    @PutMapping("sc/{fileId}")
    public int updasc(@PathVariable("fileId") int fileId){
        return service.updasc(fileId);
    }

    @PutMapping("hf/{fileId}")
    public int updahf(@PathVariable("fileId") int fileId){
        return service.updahf(fileId);
    }

    @DeleteMapping("{fileId}")
    public int delda(@PathVariable("fileId") int fileId){
        return service.delda(fileId);
    }

    @PostMapping("selbg")
    public PageVo<DFile> selbg(@RequestBody Map<String,String> map){
        PageVo<DFile> pageVo = service.selbg(map);
        return pageVo;
    }

    @PostMapping("bg")
    public int bg(@RequestBody DFile dFile,HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        return service.updabg(dFile,user.getUserName());
    }

    @PostMapping("selbywuliao")
    public PageVo<DFile> selbywuliao(@RequestBody Map<String,String> map){
        PageVo<DFile> pageVo = service.selbywuliao(map);
        return pageVo;
    }

    @PostMapping("selwuliao")
    public List<DFile> selwuliao(){
        List<DFile> selwuliao = service.selwuliao();
        return selwuliao;
    }


}
